# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.10.2)

# Declares and names the project.

project(luajava C)
set(CMAKE_C_STANDARD 99)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

include_directories(lua)
include_directories(luajava)

set(CMAKE_C_FLAGS "-DLUA_DL_DLOPEN -DLUA_USE_C89 -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_USE_LINUX -fPIE")

file(GLOB lua_files "${CMAKE_CURRENT_SOURCE_DIR}/lua/*.c")
list(FILTER lua_files EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/lua/lua.*" )
add_library(luajava SHARED luajava/luajava.c ${lua_files})

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library(log-lib log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries(luajava ${log-lib})